﻿<%@ WebHandler Language="C#" Class="SIPO.Web.AjaxHandler.Loaddata.downloadhandler" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using SIPO.Library.DataAccess.Transaction;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.Enum;
using SIPO.Web.Support;
using Newtonsoft.Json.Linq;
using SIPO.Library.DomainObject.Administration;
using SIPO.Library.DataAccess.Administration;
namespace SIPO.Web.AjaxHandler.Loaddata
{
    public class downloadhandler : SIPO.Web.BaseHandler
    {
        private recSanctionRepo recSanctionDal = new recSanctionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        private recImpositionRepo recImpositionDal = new recImpositionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        private recLogRepo logDal = new recLogRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        private recExpenseRepo recExpenseDal = new recExpenseRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        private recObjectionRepo recObjectionDal = new recObjectionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        private recDemandRepo recDemandDal = new recDemandRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        private recDevolutionRepo recDevolutionDal = new recDevolutionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        
        private string MethodName = string.Empty;
        private recRestructurRepo ResDal = new recRestructurRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);

            MethodName = context.Request.Params["method"];

            System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream);

            string jsonString = string.Empty;
            jsonString = context.Server.UrlDecode(sr.ReadToEnd());
            JObject jObj = string.IsNullOrEmpty(jsonString) ? null : JObject.Parse(jsonString);

            sr.Close();
            sr.Dispose();

            context.Response.Clear();
            context.Response.Buffer = true;

            switch (MethodName.ToLower())
            {
                case ("download"):

                    int id = Convert.ToInt32(context.Request.Params["sanction_id"]);
                    recSanction sanction = recSanctionDal.GetById(id);
                    if (sanction != null)
                    {
                        if (sanction.Attachment != null)
                        {
                            Byte[] load = (Byte[])sanction.Attachment;
                            if (sanction.AttachedFileName.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (sanction.AttachedFileName.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (sanction.AttachedFileName.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (sanction.AttachedFileName.ToLower().EndsWith(".jpeg") || sanction.AttachedFileName.ToLower().EndsWith(".jpg"))
                                context.Response.ContentType = "application/image";
                            else
                                context.Response.ContentType = "application/msword";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", sanction.AttachedFileName));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }

                    }

                    break;
                case ("downloadrestructure"):

                    int ide = Convert.ToInt32(context.Request.Params["id"]);
                    recRestructur res = ResDal.GetById(ide);
                    if (res != null)
                    {
                        if (res.AttachFile != null)
                        {
                            Byte[] load = (Byte[])res.AttachFile;
                            if (res.AttachFileName.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (res.AttachFileName.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (res.AttachFileName.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (res.AttachFileName.ToLower().EndsWith(".jpeg") || res.AttachFileName.ToLower().EndsWith(".jpg"))
                                context.Response.ContentType = "application/image";
                            else
                                context.Response.ContentType = "application/msword";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", res.AttachFileName));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }

                    }

                    break;
                case ("downloaddasarpengenaan"):

                    int impositionId = Convert.ToInt32(context.Request.Params["impositionId"]);
                    recImposition recImposition = recImpositionDal.GetById(impositionId);
                    if (recImposition != null)
                    {
                        if (recImposition.Attachment != null)
                        {
                            Byte[] load = (Byte[])recImposition.Attachment;
                            if (recImposition.AttachedFileName.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (recImposition.AttachedFileName.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (recImposition.AttachedFileName.ToLower().EndsWith(".xlsx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            else if (recImposition.AttachedFileName.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (recImposition.AttachedFileName.ToLower().EndsWith(".jpeg") || recImposition.AttachedFileName.ToLower().EndsWith(".jpg") || recImposition.AttachedFileName.ToLower().EndsWith(".gif") || recImposition.AttachedFileName.ToLower().EndsWith(".png"))
                                context.Response.ContentType = "application/image";
                            else if (recImposition.AttachedFileName.ToLower().EndsWith(".doc"))
                                context.Response.ContentType = "application/msword";
                            else if (recImposition.AttachedFileName.ToLower().EndsWith(".docx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            else if (recImposition.AttachedFileName.ToLower().EndsWith(".ppt"))
                                context.Response.ContentType = "application/vnd.ms-powerpoint";
                            else if (recImposition.AttachedFileName.ToLower().EndsWith(".pptx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", recImposition.AttachedFileName));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }
                    }

                    break;
                case ("checkfile"):
                    context.Response.Write(CheckFile(context, jObj));
                    break;
                case ("checkfiledasarpengenaan"):
                    context.Response.Write(CheckFileDasarPengenaan(context, jObj));
                    break;
                case ("checkfileexpense"):
                    context.Response.Write(CheckFileExpense(context, jObj));
                    break;
                case ("downloadexpense"):

                    int expenseid = Convert.ToInt32(context.Request.Params["expenseId"]);
                    recExpense recexpense = recExpenseDal.GetById(expenseid);
                    if (recexpense != null)
                    {
                        if (recexpense.AttachFile != null)
                        {
                            Byte[] load = (Byte[])recexpense.AttachFile;
                            if (recexpense.AttachFileName.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (recexpense.AttachFileName.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (recexpense.AttachFileName.ToLower().EndsWith(".xlsx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            else if (recexpense.AttachFileName.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (recexpense.AttachFileName.ToLower().EndsWith(".jpeg") || recexpense.AttachFileName.ToLower().EndsWith(".jpg") || recexpense.AttachFileName.ToLower().EndsWith(".gif") || recexpense.AttachFileName.ToLower().EndsWith(".png"))
                                context.Response.ContentType = "application/image";
                            else if (recexpense.AttachFileName.ToLower().EndsWith(".doc"))
                                context.Response.ContentType = "application/msword";
                            else if (recexpense.AttachFileName.ToLower().EndsWith(".docx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            else if (recexpense.AttachFileName.ToLower().EndsWith(".ppt"))
                                context.Response.ContentType = "application/vnd.ms-powerpoint";
                            else if (recexpense.AttachFileName.ToLower().EndsWith(".pptx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", recexpense.AttachFileName));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }
                    }

                    break;
                case ("checkfileobjection"):
                    context.Response.Write(CheckFileObjection(context, jObj));
                    break;
                case ("downloadobjection"):

                    int ObjectionId = Convert.ToInt32(context.Request.Params["ObjectionId"]);
                    recObjection recobjection = recObjectionDal.GetById(ObjectionId);
                    if (recobjection != null)
                    {
                        if (recobjection.ObjectionFile != null)
                        {
                            Byte[] load = (Byte[])recobjection.ObjectionFile;
                            if (recobjection.FileNameObjection.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (recobjection.FileNameObjection.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (recobjection.FileNameObjection.ToLower().EndsWith(".xlsx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            else if (recobjection.FileNameObjection.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (recobjection.FileNameObjection.ToLower().EndsWith(".jpeg") || recobjection.FileNameObjection.ToLower().EndsWith(".jpg") || recobjection.FileNameObjection.ToLower().EndsWith(".gif") || recobjection.FileNameObjection.ToLower().EndsWith(".png"))
                                context.Response.ContentType = "application/image";
                            else if (recobjection.FileNameObjection.ToLower().EndsWith(".doc"))
                                context.Response.ContentType = "application/msword";
                            else if (recobjection.FileNameObjection.ToLower().EndsWith(".docx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            else if (recobjection.FileNameObjection.ToLower().EndsWith(".ppt"))
                                context.Response.ContentType = "application/vnd.ms-powerpoint";
                            else if (recobjection.FileNameObjection.ToLower().EndsWith(".pptx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", recobjection.FileNameObjection));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }
                    }

                    break;
                case ("checkfiledemand"):
                    context.Response.Write(CheckFileDemand(context, jObj));
                    break;
                case ("downloaddemand"):

                    int DemandNo = Convert.ToInt32(context.Request.Params["DemandNo"]);
                    recDemand recDemand = recDemandDal.GetAttachFileByDemandNo(DemandNo);
                    if (recDemand != null)
                    {
                        if (recDemand.recDemandDetail.AttachFile != null)
                        {
                            Byte[] load = (Byte[])recDemand.recDemandDetail.AttachFile;
                            if (recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".xlsx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            else if (recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".jpeg") || recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".jpg") || recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".gif") || recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".png"))
                                context.Response.ContentType = "application/image";
                            else if (recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".doc"))
                                context.Response.ContentType = "application/msword";
                            else if (recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".docx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            else if (recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".ppt"))
                                context.Response.ContentType = "application/vnd.ms-powerpoint";
                            else if (recDemand.recDemandDetail.AttachFileName.ToLower().EndsWith(".pptx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", recDemand.recDemandDetail.AttachFileName));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }
                    }

                    break;
                case ("checkfiledevolution"):
                    context.Response.Write(CheckFileDevolution(context, jObj));
                    break;
                case ("downloaddevolution"):

                    int DevolutionId = Convert.ToInt32(context.Request.Params["DevolutionID"]);
                    recDevolution recDevolution = recDevolutionDal.GetAttachFileByDevolutionId(DevolutionId);
                    if (recDevolution != null)
                    {
                        if (recDevolution.AttachFile != null)
                        {
                            Byte[] load = (Byte[])recDevolution.AttachFile;
                            if (recDevolution.AttachFileName.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (recDevolution.AttachFileName.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (recDevolution.AttachFileName.ToLower().EndsWith(".xlsx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            else if (recDevolution.AttachFileName.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (recDevolution.AttachFileName.ToLower().EndsWith(".jpeg") || recDevolution.AttachFileName.ToLower().EndsWith(".jpg") || recDevolution.AttachFileName.ToLower().EndsWith(".gif") || recDevolution.AttachFileName.ToLower().EndsWith(".png"))
                                context.Response.ContentType = "application/image";
                            else if (recDevolution.AttachFileName.ToLower().EndsWith(".doc"))
                                context.Response.ContentType = "application/msword";
                            else if (recDevolution.AttachFileName.ToLower().EndsWith(".docx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            else if (recDevolution.AttachFileName.ToLower().EndsWith(".ppt"))
                                context.Response.ContentType = "application/vnd.ms-powerpoint";
                            else if (recDevolution.AttachFileName.ToLower().EndsWith(".pptx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", recDevolution.AttachFileName));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }
                    }

                    break;
                case ("checkfiledevolutionprocess"):
                    context.Response.Write(CheckFileDevolutionProcess(context, jObj));
                    break;
                case ("downloaddevolutionprocess"):
                    int DevolutionProcessDetailId = Convert.ToInt32(context.Request.Params["DevolutionProcessDetailID"]);
                    recDevolutionProcessDetail recDevolutionProcessDetail = recDevolutionDal.GetAttachFileByDevolutionProcessDetailId(DevolutionProcessDetailId);
                    if (recDevolutionProcessDetail != null)
                    {
                        if (recDevolutionProcessDetail.AttachFile != null)
                        {
                            Byte[] load = (Byte[])recDevolutionProcessDetail.AttachFile;
                            if (recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".xlsx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            else if (recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".jpeg") || recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".jpg") || recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".gif") || recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".png"))
                                context.Response.ContentType = "application/image";
                            else if (recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".doc"))
                                context.Response.ContentType = "application/msword";
                            else if (recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".docx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            else if (recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".ppt"))
                                context.Response.ContentType = "application/vnd.ms-powerpoint";
                            else if (recDevolutionProcessDetail.AttachFileName.ToLower().EndsWith(".pptx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", recDevolutionProcessDetail.AttachFileName));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }
                    }

                    break;
                case ("checkfilerespon"):
                    context.Response.Write(CheckFileRespon(context, jObj));
                    break;
                case ("downloadrespon"):

                    int ObjectionId1 = Convert.ToInt32(context.Request.Params["ObjectionId"]);
                    recObjection recobjection1 = recObjectionDal.GetById(ObjectionId1);
                    if (recobjection1 != null)
                    {
                        if (recobjection1.ResponFile != null)
                        {
                            Byte[] load = (Byte[])recobjection1.ResponFile;
                            if (recobjection1.FileNameRespon.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (recobjection1.FileNameRespon.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (recobjection1.FileNameRespon.ToLower().EndsWith(".xlsx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            else if (recobjection1.FileNameRespon.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (recobjection1.FileNameRespon.ToLower().EndsWith(".jpeg") || recobjection1.FileNameRespon.ToLower().EndsWith(".jpg") || recobjection1.FileNameRespon.ToLower().EndsWith(".gif") || recobjection1.FileNameRespon.ToLower().EndsWith(".png"))
                                context.Response.ContentType = "application/image";
                            else if (recobjection1.FileNameRespon.ToLower().EndsWith(".doc"))
                                context.Response.ContentType = "application/msword";
                            else if (recobjection1.FileNameRespon.ToLower().EndsWith(".docx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            else if (recobjection1.FileNameRespon.ToLower().EndsWith(".ppt"))
                                context.Response.ContentType = "application/vnd.ms-powerpoint";
                            else if (recobjection1.FileNameRespon.ToLower().EndsWith(".pptx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", recobjection1.FileNameRespon));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }

                    }

                    break;
                case ("checkfiledecision"):
                    context.Response.Write(CheckFileDecision(context, jObj));
                    break;
                case ("checkfilerestructure"):
                    context.Response.Write(CheckFileRestructure(context, jObj));
                    break;
                case ("downloaddecision"):

                    int ObjectionId2 = Convert.ToInt32(context.Request.Params["ObjectionId"]);
                    recObjection recobjection2 = recObjectionDal.GetById(ObjectionId2);
                    if (recobjection2 != null)
                    {
                        if (recobjection2.DecisionFile != null)
                        {
                            Byte[] load = (Byte[])recobjection2.DecisionFile;
                            if (recobjection2.FileNameDecisionFile.ToLower().EndsWith(".pdf"))
                                context.Response.ContentType = "application/pdf";
                            else if (recobjection2.FileNameDecisionFile.ToLower().EndsWith(".xls"))
                                context.Response.ContentType = "application/vnd.ms-excel";
                            else if (recobjection2.FileNameDecisionFile.ToLower().EndsWith(".xlsx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            else if (recobjection2.FileNameDecisionFile.ToLower().EndsWith(".txt"))
                                context.Response.ContentType = "application/text";
                            else if (recobjection2.FileNameDecisionFile.ToLower().EndsWith(".jpeg") || recobjection2.FileNameDecisionFile.ToLower().EndsWith(".jpg") || recobjection2.FileNameDecisionFile.ToLower().EndsWith(".gif") || recobjection2.FileNameDecisionFile.ToLower().EndsWith(".png"))
                                context.Response.ContentType = "application/image";
                            else if (recobjection2.FileNameDecisionFile.ToLower().EndsWith(".doc"))
                                context.Response.ContentType = "application/msword";
                            else if (recobjection2.FileNameDecisionFile.ToLower().EndsWith(".docx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            else if (recobjection2.FileNameDecisionFile.ToLower().EndsWith(".ppt"))
                                context.Response.ContentType = "application/vnd.ms-powerpoint";
                            else if (recobjection2.FileNameDecisionFile.ToLower().EndsWith(".pptx"))
                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

                            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", recobjection2.FileNameDecisionFile));
                            context.Response.OutputStream.Write(load, 0, load.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.OutputStream.Dispose();
                        }
                    }
                    break;
            }

        }
        private string CheckFileObjection(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["ObjectionID"].ToString().Trim());
                recObjection objection = recObjectionDal.GetById(id);
                if (objection != null)
                {
                    if (objection.ObjectionFile != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Download";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }

        private string CheckFileDemand(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["DemandNo"].ToString().Trim());
                recDemand demand = recDemandDal.GetAttachFileByDemandNo(id);
                if (demand != null)
                {
                    if (demand.recDemandDetail.AttachFile != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment recDemand tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment recDemand tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Download Demand";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }

        private string CheckFileDevolution(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["DevolutionID"].ToString().Trim());
                recDevolution devolution = recDevolutionDal.GetAttachFileByDevolutionId(id);
                if (devolution != null)
                {
                    if (devolution.AttachFile != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment recDevolution tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment recDevolution tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Download Devolution";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }

        private string CheckFileDevolutionProcess(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["DevolutionProcessDetailID"].ToString().Trim());
                recDevolutionProcessDetail devolutionProcessDetail = recDevolutionDal.GetAttachFileByDevolutionProcessDetailId(id);
                if (devolutionProcessDetail != null)
                {
                    if (devolutionProcessDetail.AttachFile != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment recDevolutionProcess tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment recDevolutionProcess tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Download DevolutionProcess";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }
        
        private string CheckFileRespon(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["ObjectionID"].ToString().Trim());
                recObjection objection = recObjectionDal.GetById(id);
                if (objection != null)
                {
                    if (objection.ResponFile != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Download";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }

        private string CheckFileDecision(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["ObjectionID"].ToString().Trim());
                recObjection objection = recObjectionDal.GetById(id);
                if (objection != null)
                {
                    if (objection.DecisionFile != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Download";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }

        private string CheckFileExpense(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["ExpenseID"].ToString().Trim());
                recExpense recexpense = recExpenseDal.GetById(id);
                if (recexpense != null)
                {
                    if (recexpense.AttachFile != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Download";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }

        private string CheckFileRestructure(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["ID"].ToString().Trim());
                recRestructur res  = ResDal.GetById(id);
                if (res != null)
                {
                    if (res.AttachFile != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Restructure Download";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }


        private string CheckFile(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["SanctionID"].ToString().Trim());
                recSanction sanction = recSanctionDal.GetById(id);
                if (sanction != null)
                {
                    if (sanction.Attachment != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Download";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }
        private string CheckFileDasarPengenaan(HttpContext context, JObject jo)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                int id = Convert.ToInt32(jo["ImpositionID"].ToString().Trim());
                recImposition recImposition = recImpositionDal.GetById(id);
                if (recImposition != null)
                {
                    if (recImposition.Attachment != null)
                    {
                        helper.IsSuccess = true;
                    }
                    else
                    {
                        helper.IsSuccess = false;
                        helper.Message = "File attachment tidak tersedia !";
                    }
                }
                else
                {
                    helper.IsSuccess = false;
                    helper.Message = "File attachment tidak tersedia !";
                }
            }
            catch (Exception ex)
            {
                helper.IsSuccess = false;
                helper.Message = ex.Message;
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Check File Download";
                log.LogMessage = helper.Message;
                log.LogSource = "donwloadhandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }

        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}